package com.example.horizonserver.controller;


import com.example.horizonserver.common.result.PageResult;
import com.example.horizonserver.common.result.Result;
import com.example.horizonserver.pojo.DTO.*;
import com.example.horizonserver.pojo.VO.DispatchSubmitVO;
import com.example.horizonserver.pojo.VO.MaintainSubmitVO;
import com.example.horizonserver.service.MaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/maintains")
public class MaintainController {

    @Autowired
    private MaintainService maintainService;

    /**
     * 用户发起保修/维护申请
     * @param maintainSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<MaintainSubmitVO> submit(@RequestBody MaintainSubmitDTO maintainSubmitDTO)
    {
        MaintainSubmitVO maintainSubmitVO = maintainService.submitMaintain(maintainSubmitDTO);
        return Result.success(maintainSubmitVO);
    }

    /**
     * 管理员  收到通知申请 点击去维护
     *
     * @return
     */
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody MaintainConfirmDTO maintainConfirmDTO) {
        maintainService.confirm(maintainConfirmDTO);
        return Result.success();
    }

    /**
     * 完成维护 归还车辆 录入维护费用
     *
     * @return
     */
    @PutMapping("/complete")
    public Result<String> complete(@RequestBody MaintainCompleteDTO maintainCompleteDTO) {
        maintainService.complete(maintainCompleteDTO);
        return Result.success();
    }

    /**
     * 条件分页查询维护记录
     *
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(MaintainPageQueryDTO maintainPageQueryDTO)
    {
        PageResult pageResult = maintainService.page(maintainPageQueryDTO);
        return Result.success(pageResult);
    }

}
